﻿Public Class frmKhachHang


    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

        Dim sql As String = "select * from KhachHang"
        Dim DATA As New ketnoidulieu()
        dgvkhachhang.DataSource = DATA.ExcuteDataTable(sql)
    End Sub

    Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click
        Dim sql As String = String.Format("Insert into KhachHang(MaHopDong,HoTen,DiaChi,DienThoai) values ('" & txtmahopdong.Text & "','" & txthoten.Text & "','" & txtdiachi.Text & "', '" & txtdienthoai.Text & "')")
        Dim INS As New ketnoidulieu()
        INS.SQL_ExecuteNonQuery(sql)
        Dim sl As String = "select * from KhachHang"
        dgvkhachhang.DataSource = INS.ExcuteDataTable(sl)
    End Sub

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        If txtmahopdong.Text = "" Then
            MsgBox(" Bạn Phải Nhập Giá Trị Cấn Xóa !!! ")
        Else
            Dim sql As String = String.Format("delete * from Nha where MaHopDong = '" & txtmahopdong.Text & "'")
            Dim KN As New ketnoidulieu()
            KN.SQL_ExecuteNonQuery(sql)
            Dim sl As String = "select * from KhachHang"
            dgvkhachhang.DataSource = KN.ExcuteDataTable(sl)
        End If
    End Sub

    Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click
        Dim sql As String = String.Format("Update KhachHang Set HoTen = N'{0}', DiaChi = N'{1}', DienThoai ='{2}' where MaHopDong = '" & txtmahopdong.Text & "'", txthoten.Text, txtdiachi.Text, txtdienthoai.Text)
        Dim INS As New ketnoidulieu()
        INS.SQL_ExecuteNonQuery(sql)
        Dim sl As String = "select * from KhachHang"
        dgvkhachhang.DataSource = INS.ExcuteDataTable(sl)
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click
        Dim sql As String = String.Format("select * from KhachHang where  DiaChi=N'{0}' or MaHopDong='{1}' or HoTen=N'{2}'", txtdc.Text, txtmhd.Text, txtht.Text)
        Dim DATA As New ketnoidulieu()
        dgvkhachhang.DataSource = DATA.ExcuteDataTable(sql)
    End Sub
End Class